import os
import constants
from flask import request
from SQLOperation.PatientSQLOperation import PatientSQLOperation
from SQLConfig import app
from updateProjectFile import changeProjectFile

@app.route('/deleteStlFile', methods=['Get', 'POST'])
def deleteStlFile():  # put application's code here
    """
    删除患者
    """
    if request.method == 'POST':
        patientId=request.json.get("patientId")
        index=request.json.get("index")
    elif request.method == 'GET':
        patientId=request.args.get("patientId") 
        index=request.args.get("index")
    patientId=str(patientId)

    index=int(index)
    filename=changeProjectFile(patientId,"stlFiles","select",index,0)
    os.remove(os.path.join(constants.patientBaseUrl,patientId,constants.patientStlUrl,filename["filename"]))
    changeProjectFile(patientId,"stlFiles","delete",index,0)
    return "OK"
